#ifndef __MEMORY_STREAM_H__
#define __MEMORY_STREAM_H__

#include "stream.h"

#define MEMORYSTREAM_CAST(x) ((MemoryStream *)(x))

typedef struct _MemoryStream
{
  Stream stream;

  char *buff;
  int buff_size;
  int buff_off;
  int nbytes;
} MemoryStream;

void memorystream_create (MemoryStream *ms, int init_size);
/* Returns a pointer to the offset byte of the stream.
 * Used to access memory directly. */
void * memorystream_pointer_from_offset (MemoryStream *ms, int offset);

static void memorystream_write (Stream *s, void *src, int size);
static int memorystream_read (Stream *s, void *dest, int num_read,
                               int dest_offset);
static void memorystream_seek (Stream *s, int offset, SeekWhence whence);
static int memorystream_pos (Stream *s);
static int memorystream_size (Stream *s);
static void memorystream_close (Stream *s);

static void memorystream_expand_buffer (MemoryStream *ms);

#endif
